using Firestarter.DB.Schema.BO;
using Firestarter.DB.Schema.Test.BO.TestUtils;
using FireStarterModeller.BO;
using FireStarterModeller.Test;
using NUnit.Framework;
namespace Firestarter.DB.Schema.Test.BO
{
    /// <summary>
    /// Provides a place to write custom tests for DBForeignKeyColumn objects.
    /// This file is only written once and can be changed.  The Def file
    /// attached to this as a dependent is rewritten with each regeneration
    /// and contains the standard tests for DBForeignKeyColumn.
    /// Regenerate this test project whenever there have been changes to the
    /// business objects.
    /// If tests are failing due to a unique setup in your application,
    /// you can either override the Create methods in TestUtils, or you
    /// can add the test to the ignore list below and reimplement it here.
    /// </summary>
    public partial class TestDBForeignKeyColumn
    {
        [TestFixtureSetUp]
        public void SetupTestFixture()
        {
            //------------------------------------------------------------
            // Use this list to ignore generated tests that are failing
            // due to a unique condition in your application.
            // Remember to reimplement the test here.
            //------------------------------------------------------------
            //_ignoreList.Add("TestMethodName", "Reason for ignoring it");
            base.SetupFixture();
        }
        
        [Test]
        public void Test_ToString()
        {
            //---------------Set up test pack-------------------
            DBForeignKeyColumn keyColumn = TestUtilsDBForeignKeyColumn.CreateUnsavedValidDBForeignKeyColumn();
            //---------------Assert Preconditions ----------------
            Assert.IsNotNull(keyColumn.ForeignKey);
            Assert.IsNotNull(keyColumn.ParentColumn);
            Assert.IsNotNull(keyColumn.ParentColumn.ColumnName);
            //---------------Execute Test ----------------------
            string actualToString = keyColumn.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(keyColumn.ForeignKey.ForeignKeyName + " - " + keyColumn.ParentColumn.ColumnName + "_" + keyColumn.RelatedColumn.ColumnName, actualToString);
        }


        [Test]
        public void Test_ParentColumnName_WhenColumnNull_ShouldRetEmptyString()
        {
            //---------------Set up test pack-------------------
            DBForeignKeyColumn pkColumn = new DBForeignKeyColumn();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(pkColumn);
            Assert.IsNull(pkColumn.ParentColumn);
            //---------------Execute Test ----------------------
            string columnName = pkColumn.ParentColumnName;
            //---------------Test Result -----------------------
            Assert.IsEmpty(columnName);
        }

        [Test]
        public void Test_ParentColumnName_WhenColumnNotNull_ShouldRetDBColumnName()
        {
            //---------------Set up test pack-------------------
            DBForeignKeyColumn pkColumn = new DBForeignKeyColumn();
            string expectedColumnName = GetRandomString();
            pkColumn.ParentColumn = new DBColumn(expectedColumnName);
            //---------------Assert Precondition----------------
            Assert.IsNotNull(pkColumn);
            Assert.IsNotNull(pkColumn.ParentColumn);
            Assert.IsNotNullOrEmpty(pkColumn.ParentColumn.ColumnName);
            //---------------Execute Test ----------------------
            string columnName = pkColumn.ParentColumnName;
            //---------------Test Result -----------------------
            Assert.AreEqual(expectedColumnName, columnName);
        }

        [Test]
        public void Test_RelatedColumnName_WhenColumnNull_ShouldRetEmptyString()
        {
            //---------------Set up test pack-------------------
            DBForeignKeyColumn pkColumn = new DBForeignKeyColumn();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(pkColumn);
            Assert.IsNull(pkColumn.RelatedColumn);
            //---------------Execute Test ----------------------
            string columnName = pkColumn.RelatedColumnName;
            //---------------Test Result -----------------------
            Assert.IsEmpty(columnName);
        }

        [Test]
        public void Test_RelatedColumnName_WhenColumnNotNull_ShouldRetDBColumnName()
        {
            //---------------Set up test pack-------------------
            DBForeignKeyColumn pkColumn = new DBForeignKeyColumn();
            string expectedColumnName = GetRandomString();
            pkColumn.RelatedColumn = new DBColumn(expectedColumnName);
            //---------------Assert Precondition----------------
            Assert.IsNotNull(pkColumn);
            Assert.IsNotNull(pkColumn.RelatedColumn);
            Assert.IsNotNullOrEmpty(pkColumn.RelatedColumn.ColumnName);
            //---------------Execute Test ----------------------
            string columnName = pkColumn.RelatedColumnName;
            //---------------Test Result -----------------------
            Assert.AreEqual(expectedColumnName, columnName);
        }


        [Test]
        public void Test_ParentPropertyName_WhenColumnNull_ShouldRetEmptyString()
        {
            //---------------Set up test pack-------------------
            DBForeignKeyColumn pkColumn = new DBForeignKeyColumn();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(pkColumn);
            Assert.IsNull(pkColumn.ParentColumn);
            //---------------Execute Test ----------------------
            string propName = pkColumn.GetParentPropertyName();
            //---------------Test Result -----------------------
            Assert.IsEmpty(propName);
        }


        [Test]
        public void Test_ParentPropertyName_WhenColumnNotNullAndPropertNull_ShouldRetEmptyString()
        {
            //---------------Set up test pack-------------------
            DBForeignKeyColumn pkColumn = new DBForeignKeyColumn();
            pkColumn.ParentColumn = new DBColumn();
            string expectedColumnName = GetRandomString();
            pkColumn.ParentColumn = new DBColumn(expectedColumnName);
            //---------------Assert Precondition----------------
            Assert.IsNotNull(pkColumn);
            Assert.IsNotNull(pkColumn.ParentColumn);
            //---------------Execute Test ----------------------
            string propName = pkColumn.GetParentPropertyName();
            //---------------Test Result -----------------------
            Assert.IsEmpty(propName);
        }
        [Test]
        public void Test_ParentPropertyName_WhenColumnNotNullAndPropertNotNull_ShouldRetPropertyName()
        {
            //---------------Set up test pack-------------------
            DBForeignKeyColumn pkColumn = new DBForeignKeyColumn();
            string expectedPropName = GetRandomString();
            pkColumn.ParentColumn = new DBColumn();
            var mappedDMProperty = new DMProperty();
            mappedDMProperty.PropertyName = expectedPropName;
            pkColumn.ParentColumn.SetMappedDMProperty(mappedDMProperty);
            //---------------Assert Precondition----------------
            Assert.IsNotNull(pkColumn);
            Assert.IsNotNull(pkColumn.ParentColumn);
            Assert.IsNotNullOrEmpty(pkColumn.ParentColumn.GetMappedDMProperty().PropertyName);
            //---------------Execute Test ----------------------
            string propName = pkColumn.GetParentPropertyName();
            //---------------Test Result -----------------------
            Assert.AreEqual(expectedPropName, propName);
        }

        [Test]
        public void Test_RelatedPropertyName_WhenColumnNull_ShouldRetEmptyString()
        {
            //---------------Set up test pack-------------------
            DBForeignKeyColumn pkColumn = new DBForeignKeyColumn();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(pkColumn);
            Assert.IsNull(pkColumn.RelatedColumn);
            //---------------Execute Test ----------------------
            string propName = pkColumn.GetRelatedPropertyName();
            //---------------Test Result -----------------------
            Assert.IsEmpty(propName);
        }


        [Test]
        public void Test_RelatedPropertyName_WhenColumnNotNullAndPropertNull_ShouldRetEmptyString()
        {
            //---------------Set up test pack-------------------
            DBForeignKeyColumn pkColumn = new DBForeignKeyColumn();
            pkColumn.RelatedColumn = new DBColumn();
            string expectedColumnName = GetRandomString();
            pkColumn.RelatedColumn = new DBColumn(expectedColumnName);
            //---------------Assert Precondition----------------
            Assert.IsNotNull(pkColumn);
            Assert.IsNotNull(pkColumn.RelatedColumn);
            //---------------Execute Test ----------------------
            string propName = pkColumn.GetRelatedPropertyName();
            //---------------Test Result -----------------------
            Assert.IsEmpty(propName);
        }
        [Test]
        public void Test_RelatedPropertyName_WhenColumnNotNullAndPropertNotNull_ShouldRetPropertyName()
        {
            //---------------Set up test pack-------------------
            DBForeignKeyColumn pkColumn = new DBForeignKeyColumn();
            string expectedPropName = GetRandomString();
            pkColumn.RelatedColumn = new DBColumn();
            var mappedDMProperty = new DMProperty();
            mappedDMProperty.PropertyName = expectedPropName;
            pkColumn.RelatedColumn.SetMappedDMProperty(mappedDMProperty);
            //---------------Assert Precondition----------------
            Assert.IsNotNull(pkColumn);
            Assert.IsNotNull(pkColumn.RelatedColumn);
            Assert.IsNotNullOrEmpty(pkColumn.RelatedColumn.GetMappedDMProperty().PropertyName);
            //---------------Execute Test ----------------------
            string propName = pkColumn.GetRelatedPropertyName();
            //---------------Test Result -----------------------
            Assert.AreEqual(expectedPropName, propName);
        }


        [Test]
        public void Test_RelatedTableName_WhenColumnNull_ShouldRetEmptyString()
        {
            //---------------Set up test pack-------------------
            DBForeignKeyColumn pkColumn = new DBForeignKeyColumn();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(pkColumn);
            Assert.IsNull(pkColumn.RelatedColumn);
            //---------------Execute Test ----------------------
            string tableName = pkColumn.RelatedTableName;
            //---------------Test Result -----------------------
            Assert.IsEmpty(tableName);
        }


        [Test]
        public void Test_RelatedTableName_WhenColumnNotNullAndTableNull_ShouldRetEmptyString()
        {
            //---------------Set up test pack-------------------
            DBForeignKeyColumn pkColumn = new DBForeignKeyColumn();
            pkColumn.RelatedColumn = new DBColumn();
            string expectedColumnName = GetRandomString();
            pkColumn.RelatedColumn = new DBColumn(expectedColumnName);
            //---------------Assert Precondition----------------
            Assert.IsNotNull(pkColumn);
            Assert.IsNull(pkColumn.RelatedColumn.Table);
            //---------------Execute Test ----------------------
            string tableName = pkColumn.RelatedTableName;
            //---------------Test Result -----------------------
            Assert.IsEmpty(tableName);
        }
        [Test]
        public void Test_RelatedTableName_WhenColumnNotNullAndTableNotNull_ShouldRetTableName()
        {
            //---------------Set up test pack-------------------
            DBForeignKeyColumn pkColumn = new DBForeignKeyColumn();
            string expectedTableName = GetRandomString();
            pkColumn.RelatedColumn = new DBColumn();
            var mappedDBTable = new DBTable();
            mappedDBTable.TableName = expectedTableName;
            pkColumn.RelatedColumn.Table = mappedDBTable;
            //---------------Assert Precondition----------------
            Assert.IsNotNull(pkColumn);
            Assert.IsNotNull(pkColumn.RelatedColumn);
            Assert.IsNotNullOrEmpty(pkColumn.RelatedColumn.Table.TableName);
            //---------------Execute Test ----------------------
            string tableName = pkColumn.RelatedTableName;
            //---------------Test Result -----------------------
            Assert.AreEqual(expectedTableName, tableName);
        }

        private static string GetRandomString()
        {
            return TestUtilsShared.GetRandomString();
        }
    }
}